package org.codersunit.radboid.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;

public class NamedEntityMap {
	private Node root; 
	
	private class Ref<T> {
		public T item;
		public Ref()
		{
			item = null;
		}
	}
	
	private class Node {
		private String currentPath;
		public char current;
		public char value;
		private HashMap<Character, Node> children;
		
		public Node()
		{
			currentPath = null;
			current = 0;
			children = new HashMap<Character, Node>();
		}
		
		public Node(String parentPath, char current)
		{
			this();
			currentPath = parentPath + current;
			this.current = current;
		}
		
		public Node(String parentPath, char current, char value)
		{
			this(parentPath, current);
			this.value = value;
		}
		
		public boolean tryGetChild(char search, Ref<Node> child)
		{
			if(children.containsKey(search)) {
				child.item = children.get(search);
				return true;
			}
			return false;
		}
		
		public Node getChild(char search) 
		{
			return children.get(search);
		}
		
		public boolean hasChild(char search) 
		{
			return children.containsKey(search);
		}
		
		public String getPath()
		{
			return currentPath;
		}
		
		public void addChild(char name, Node child)
		{
			
		}
	}
	
	public NamedEntityMap() {
		this.root = new Node();
		
		this.put("quot", '"');
		this.put("amp", '&');
		this.put("apos", '\'');
		this.put("lt", '<');
		this.put("gt", '>');
	}
	
	private void put(String entity, char value) 
	{
		char[] key = entity.toCharArray();
		Node current = this.root;
		for(int i = 0; i < key.length; i++) {
			char search = key[i];
			if(current.hasChild(search)) {
				current = current.getChild(search);
			} else {
				Node child = new Node(current.getPath(), search);
				current.addChild(search, child);
				current = child;
			}
		}
		current.value = value;
	}
	
	public boolean containsPartial(String input) 
	{
		return false;
	}
}
